from django.db import models

from apps.interface.models import InterfaceModel


# Create your models here.
class PerformanceModel(models.Model):
    class Meta:
        db_table = 'performance'
        verbose_name = '性能测试'
        verbose_name_plural = verbose_name

    STATUS_CHOICES = ((0, '未测试'), (1, '测试中'), (2, '测试完成'))

    interface_id = models.ForeignKey(to=InterfaceModel, on_delete=models.CASCADE, verbose_name='接口id')
    time_ctrl = models.IntegerField(verbose_name='压测时长')
    rps = models.IntegerField(verbose_name='每秒请求上限')
    step_len = models.TextField(null=False, verbose_name='步长')
    status = models.IntegerField(choices=STATUS_CHOICES, verbose_name='状态')

    def __str__(self):
        return self.interface_id.name + '(' + self.STATUS_CHOICES[self.status] + ')'


class PerformanceLogModel(models.Model):
    class Meta:
        db_table = 'performance_log'
        verbose_name = '性能测试记录'
        verbose_name_plural = verbose_name

    performance_id = models.ForeignKey(to=PerformanceModel, on_delete=models.CASCADE, verbose_name='性能测试id')
    http_status = models.IntegerField(verbose_name='响应状态码')
    http_response_time = models.IntegerField(verbose_name='响应时间')
    http_request_size = models.IntegerField(verbose_name='请求大小')
    http_response_size = models.IntegerField(verbose_name='响应大小')

    def __str__(self):
        return self.http_status
